#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "../chat/chat.h"
#include "../contacts/contacts.h"
#include "../application/application.h"
#include "../profile/profile.h"
#include "../login/mylogin.h"
#include <QMouseEvent>
#include "../../route/responsestruct.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE


class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void beforeShow();
    void afterShow();

    void styleSelf();
    void styleAvatar(responseUserInfo userinfo);
    void initTab();
    bool eventFilter(QObject *obj, QEvent *event);//事件过滤器钩子
    void initProfile();
    void initDataFromServer();
    void setMyLogin(MyLogin* mylogin);
    void setUid(int uid);
    void setUserInfo(responseUserInfo userInfo);
public:
    //登陆回调
    void apiLoginCallback(int code, QString msg, responseLogin* data, responseUserInfo userinfo);
    //获取用户信息回调
    void apiGetUserInfoCallback(int code, QString msg, responseUserInfo* data);
    //获取好友列表回调
    void apiFriendList(int code, QString msg, responseGroupList* data);

    /**
     * @brief 处理对方发来的聊天消息
     * @param code
     * @param msg
     */
    void apiRecvChatCallback(int code, QString msg, responseRecvChat* data);

    /**
     * @brief 刷新总数
     * @param str
     */
    void refreshAllUnreadNum(QString str);

public:
    static const int WINDOW_WIDTH = 865;//窗口宽
    static const int WINDOW_HEIGHT = 633;//窗口高
    static const int WINDOW_BANNER_HEIGHT = 53;//banner高
    static const int WINDOW_LEFT_SCROLL_WIDTH = 180;//左侧scroll区宽200
    static const int WINDOW_BODY_HEIGHT = WINDOW_HEIGHT - WINDOW_BANNER_HEIGHT;//body高
    static const int WINDOW_BODY_WIDTH = WINDOW_WIDTH - WINDOW_LEFT_SCROLL_WIDTH;//body宽

    static const int WINDOW_CHAT_BANNER_HEIGHT = 45;//CHAT的banner高
    static const int WINDOW_CHAT_SCROLL_HEIGHT = 350;//chat的聊天记录高
    static const int WINDOW_CHAT_MENU_HEIGHT = 35;//chat的menu高

    static const int CURRENT_CLICKED_TAB_CHAT = 1;//当前选中的tab为chat
    static const int CURRENT_CLICKED_TAB_CONTACTS = 2;
    static const int CURRENT_CLICKED_TAB_APPLICATION = 3;

    Chat *chat;
    Contacts *contacts;
    Application *application;
    MyLogin *mylogin;
    int uid;
    responseUserInfo userInfo;
    int currentClickedTab;//当前选中的tab

public slots:
    void on_leftCloseButton_clicked();

    void on_leftMinButton_clicked();

    void on_leftMaxButton_clicked();

    void on_appButton_clicked();

    void on_contactsButton_clicked();

    void on_chatButton_clicked();

private:
    void setCurrentClickedTab(int currentTab);

private:
    /**
     * @brief 顶部左侧关闭按钮样式
     */
    const QString LEFT_CLOSE_BUTTON_STYLE = "QPushButton{background:transparent;border-image:url(:/icon/source/main/left-close-down.png)}"
                                            "QPushButton:hover{background:transparent;border-image:url(:/icon/source/main/left-close.png)}"
                                            "QPushButton:pressed{background:transparent;border-image:url(:/icon/source/main/left-close.png)}";
    /**
     * @brief 顶部左侧放小按钮
     */
    const QString LEFT_MIN_BUTTON_STYLE = "QPushButton{background:transparent;border-image:url(:/icon/source/main/left-close-down.png)}"
                                          "QPushButton:hover{background:transparent;border-image:url(:/icon/source/main/left-min.png)}"
                                          "QPushButton:pressed{background:transparent;border-image:url(:/icon/source/main/left-min.png)}";
    /**
     * @brief 顶部左侧放大按钮
     */
    const QString LEFT_MAX_BUTTON_STYLE = "QPushButton{background:transparent;border-image:url(:/icon/source/main/left-close-down.png)}"
                                          "QPushButton:hover{background:transparent;border-image:url(:/icon/source/main/left-max.png)}"
                                          "QPushButton:pressed{background:transparent;border-image:url(:/icon/source/main/left-max.png)}";

    /**
     * @brief banner聊天按钮 未选中状态
     */
    const QString CHAT_BUTTON_NORMAL_STYLE = "QPushButton{background:transparent;border-image:url(:/icon/source/main/menu-message-normal-2x.png)}";
    const QString CHAT_BUTTON_DOWN_STYLE = "QPushButton{background:transparent;border-image:url(:/icon/source/main/menu-message-down-2x.png)}";

    /**
     * @brief banne联系人按钮
     */
    const QString CONTACTS_BUTTON_NORMAL_STYLE = "QPushButton{background:transparent;border-image:url(:/icon/source/main/menu-contact-normal-2x.png)}";
    const QString CONTACTS_BUTTON_DOWN_STYLE = "QPushButton{background:transparent;border-image:url(:/icon/source/main/menu-contact-down-2x.png)}";

    /**
     * @brief banner应用按钮
     */
    const QString APPLICATION_BUTTON_NORMAL_STYLE = "QPushButton{background:transparent;border-image:url(:/icon/source/main/menu-more-normal-2x.png)}";
    const QString APPLICATION_BUTTON_DOWN_STYLE = "QPushButton{background:transparent;border-image:url(:/icon/source/main/menu-more-down-2x.png)}";
protected:
    virtual void resizeEvent(QResizeEvent *event);

private:
    Ui::MainWindow *ui;
    Profile *profile;
    bool IS_FULL_SCREEN = false;
    QLabel* chatUnreadNum = nullptr;

};
#endif // MAINWINDOW_H
